package de.koller.transit.input;

import de.koller.aframe.plain.InputPlain;
import de.koller.transit.TNode;
import java.awt.event.KeyEvent;

public class TInput extends TNode {
	private InputPlain input;

	@Override
	protected void init() {
		super.init();
		
		input = new InputPlain( troot.display );
		this.addChild( input );
	}

	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
		if( input.isKeyPressed( KeyEvent.VK_F12 ) )
			troot.stop();
		
		playerASteering( elapsedTime );
		playerBSteering( elapsedTime );
	}

	private void playerASteering( int elapsedTime ) {
		boolean left, right;
		left = input.isKeyDown( KeyEvent.VK_LEFT );
		right = input.isKeyDown( KeyEvent.VK_RIGHT );
		troot.engine.brushContainer.playerA.steer( left, right, elapsedTime );	
	}
	
	private void playerBSteering( int elapsedTime ) {
		boolean left, right;
		left = input.isKeyDown( KeyEvent.VK_A );
		right = input.isKeyDown( KeyEvent.VK_D );
		troot.engine.brushContainer.playerB.steer( left, right, elapsedTime );	
	}
}
